#!/usr/bin/python
#coding: utf-8

from PIL import Image
import os
import os.path
import time

#用于修改图片尺寸，以满足IOS各设备尺寸
#3.5英寸		-		960 x 640
#4英寸		-		1136 x 640
#4.7英寸		-		1334 x 750
#5.5英寸		-		2208 x 1242
#Ipad		-		1024 x 768
#Ipad Pro	-		2732 x 2048

dirnames = ['3.5', '4', '4.7', '5.5', 'ipad', 'ipadPro']
size = [(960, 640), (1136, 640), (1334, 750), (2208, 1242), (1024, 768), (2732, 2048)]
rootdir = "./"

#清空目录下除图片的其他文件
filenames = os.listdir(rootdir)
print "===== 正在裁剪 ====="
t1 = time.clock()
#获取当前目录下的图片
for filename in filenames:
	if(filename[-3:] == 'jpg' or filename[-4:] == 'jpeg' or filename[-3:] == 'png'):
		print filename
		img = Image.open(filename)
		for i in range(0,len(dirnames)):
			if not os.path.exists(dirnames[i]):
				os.makedirs(dirnames[i])
			newImg = img.resize(size[i])
			newImg.save(dirnames[i] + '/' + filename)

print "===== 大功告成 ====="
print "耗时:", time.clock() - t1, 's'